<?php

namespace App\Http\Services\Member;

use App\Models\MemberFavorite;
use App\Models\MemberThumbsUp;

class MemberService {

    public static function updateMyFavorite($member_id, $to_member_id, $is_favorite = 1)
    {
        if ($is_favorite)
        {
            #是否存在
            $existMemberFavorite = MemberFavorite::query()
                ->where([
                    ['member_id',$member_id],
                    ['to_member_id',$to_member_id],
                ])
                ->first();

            if (!$existMemberFavorite)
            {
                MemberFavorite::saveEntity([
                    'member_id' => $member_id,
                    'to_member_id' => $to_member_id,
                ]);
            }
        }else{
            MemberFavorite::query()
                ->where([
                    ['member_id',$member_id],
                    ['to_member_id',$to_member_id],
                ])
                ->delete();
        }

        return true;
    }


    public static function updateMyThumbsUp($member_id, $to_member_id, $isThumbsUp = 1)
    {

        if ($isThumbsUp)
        {
            #是否存在
            $existMemberFavorite = MemberThumbsUp::query()
                ->where([
                    ['member_id',$member_id],
                    ['to_member_id',$to_member_id],
                ])
                ->first();

            if (!$existMemberFavorite)
            {
                MemberThumbsUp::saveEntity([
                    'member_id' => $member_id,
                    'to_member_id' => $to_member_id,
                ]);
            }
        }else{
            MemberThumbsUp::query()
                ->where([
                    ['member_id',$member_id],
                    ['to_member_id',$to_member_id],
                ])
                ->delete();
        }

        return true;
    }

}